<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Video Player</title>
  <style>
    .video-container {
      max-width: 800px;
      margin: 0 auto;
      padding: 20px;
    }
    video {
      width: 100%;
      height: auto;
    }
  </style>
</head>
<body>
  <div class="video-container">
    <button id="autoDownload">立即下载视频</button>
    <video id="myVideo" controls preload="metadata">
      <source src="<%= videoUrl %>" type="video/mp4">
      <source src="<%= videoUrl %>" type="video/webm">
      <source src="<%= videoUrl %>" type="video/avi">
      <source src="<%= videoUrl %>" type="video/quicktime">
      <source src="<%= videoUrl %>" type="video/ogg">
      Your browser does not support the video tag.
    </video>
    <a id="download" referrerpolicy="no-referrer" download href="<%= videoUrl %>">下载链接</a>
  </div>

  <script>
    const video = document.getElementById('myVideo');

    video.addEventListener('loadedmetadata', () => {
    console.log('视频时长:', video.duration, '秒');
    document.body.insertAdjacentHTML('beforeend', `<div class='duration'>${video.duration.toFixed(2)}</div>`);
    document.querySelector('duration').textContent = `${video.duration.toFixed(2)}`;
    });

    // 可选：添加错误处理
    video.addEventListener('error', (e) => {
      console.error('加载视频出错:', e);
    });


    const btn = document.getElementById('autoDownload');

btn.addEventListener('click', () => {
  const src = video.currentSrc || video.src;
  const name = src.split('/').pop().split('?')[0];
  const a = document.createElement('a');
  a.href = src;
  a.download = name;
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
});

    
  </script>
  
</body>
</html>
